using UnityEngine;
using System.Collections;

public class Game : MonoBehaviour {
	
	//fundo
	public Texture2D bg;
	public Texture2D bg_2;
	public int bgPositionX;
	public int bgPositionY;
	public int bgScaleX;
	public int bgScaleY;
	
	public Texture2D bg2;
	public Texture2D bg2_1;
	public int bg2PositionX;
	public int bg2PositionY;
	public int bg2ScaleX;
	public int bg2ScaleY;
	
	public bool state_bg;
	public bool state_bg2;
	
	//player1
	public Texture2D player1;
	public Texture2D player1_2;
	public float player1Vel;
	public float player1PositionX;
	public int player1PositionY;
	public int player1ScaleX;
	public int player1ScaleY;
	
	
	public bool state_player1 = true;
	public bool state_player2 = true;
	
	//player2
	public Texture2D player2;
	public Texture2D player2_1;
	public float player2Vel;
	public float player2PositionX;
	public int player2PositionY;
	public int player2ScaleX;
	public int player2ScaleY;
	
    void Start()
    {	
		//fundo
		state_bg = true;
		state_bg2 = true;
		//bg = (Texture2D)Resources.Load("Textures/Remo_BgJogo.jpg");
		bgPositionY = 0;
		bgPositionX = 0;
		bgScaleX = 800;
		bgScaleY = 600;
		
		bg2PositionY = 0;
		bg2PositionX = 0;
		bg2ScaleX = 800;
		bg2ScaleY = 600;
		
		//posiçao player1
		
		//player1 = (Texture2D)Resources.Load("Remo_SpritePersonagem1_1.png");
		player1PositionX = 0;
		player1PositionY = 102;
		player1ScaleX = 256;
		player1ScaleY = 128;
		
		//posiçao player2
		
		//player2 = (Texture2D)Resources.Load("Textures/Remo_SpritePersonagem2_1.png");
		player2PositionX = 0;
		player2PositionY = 402;
		player2ScaleX = 256;
		player2ScaleY = 128;
		
    }

    void Update()
    {
		
		if(player1PositionX >= 800 - player1ScaleX / 2)
		{
			state_bg = false;
			player1PositionX = player1ScaleX / 2 * -1;
		}
		else if( player1PositionX >= 650 - player1ScaleX /2 && state_bg == false)
		{
			Debug.LogError("PQP FOIIIII");
		}
		
		if(player2PositionX >= 800 - player2ScaleX / 2)
		{
			state_bg2 = false;
			player2PositionX = player2ScaleX / 2 * -1;
		}
		else if( player2PositionX >= 650 - player2ScaleX /2 && state_bg2 == false)
		{
			Debug.LogError("PQP FOIIIII");
		}
		
		
		
		
		
		//movimentaçao player1 e "Animaçao"
		if(Input.GetKeyDown(KeyCode.A))
		{
			player1PositionX += 350*Time.deltaTime;
			state_player1 = true;
		}
		if(Input.GetKeyDown(KeyCode.D))
		{
			player1PositionX += 350*Time.deltaTime;
			state_player1 = false;
		}
		
		//movimentaçao player2
		if(Input.GetKeyDown(KeyCode.LeftArrow))
		{
			player2PositionX += 350*Time.deltaTime;	
			state_player2 = true;
		}
		
		if(Input.GetKeyDown(KeyCode.RightArrow))
		{
			player2PositionX += 350*Time.deltaTime;	
			state_player2 = false;
		}
	

    }

    void OnGUI()
	{		
		//fundo
		switch(state_bg)
		{
			case true:
				GUI.DrawTexture(new Rect(bgPositionX, bgPositionY, bgScaleX,bgScaleY), bg);
				break;
			case false:
				GUI.DrawTexture(new Rect(bgPositionX, bgPositionY, bgScaleX,bgScaleY), bg_2);
				break;
		}
		
		switch(state_bg2)
		{
			case true:
				GUI.DrawTexture(new Rect(bg2PositionX, bg2PositionY, bg2ScaleX,bg2ScaleY), bg2);
				break;
			case false:
				GUI.DrawTexture(new Rect(bg2PositionX, bg2PositionY, bg2ScaleX,bg2ScaleY), bg2_1);
				break;
		}
		
		
	
		
		//player1
		switch(state_player1)
		{		
		case true:
			GUI.DrawTexture(new Rect(player1PositionX, player1PositionY, 256, 128), player1);
			break;
		case false:
			GUI.DrawTexture(new Rect(player1PositionX, player1PositionY, 256, 128), player1_2);
			break;
		}
		
		
		
		
		switch(state_player2)
		{		
		case true:
			GUI.DrawTexture(new Rect(player2PositionX, player2PositionY, player2ScaleX, player2ScaleY), player2);
			break;
				
		case false:
			GUI.DrawTexture(new Rect(player2PositionX, player2PositionY, player2ScaleX, player2ScaleY), player2_1);
			break;
		}
		
	
	}
}